$(function() {
  var formatDate = function(n) {
    var date = new Date(n * 1000);
    return [ date.getFullYear(), date.getMonth() + 1, date.getDate() ].join(' / ');
  }
  $.getJSON(
    '-/get-corpus-stats?callback=?',
    null,
    function(r) {
      $.each(r.tables, function(key, value) {
        $('#' + key + '-count').text(formatInteger(value));
      })
      
      if (r.earliest) {
        $('#earliest-post').text(formatDate(r.earliest));
      }
      if (r.latest) {
        $('#latest-post').text(formatDate(r.latest));
      }
    },
    'jsonp'
  );
});